package club.babyf.nativeai.demo.algorithm;

/**
 * _23_FindTwoSumOrder.
 *
 * @author zhanglei.
 * @date 2025/7/26 08:23.
 * @description 有序数组的两数之和.
 */
public class _23_FindTwoSumOrder {

    public static int[] findTwoSumOrder(int[] arr, int target) {
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            int currentSum = arr[left] + arr[right];
            if (currentSum == target) {
                return new int[] {arr[left], arr[right]};
            } else if (currentSum < target) {
                left++;
            } else {
                right--;
            }
        }
        return new int[] {};
    }

    private static void print(int[] arr) {
        for (int i : arr) {
            System.out.print(i + " | ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        int[] arr = {1, 3, 5, 7, 9};
        int[] twoSumOrder = findTwoSumOrder(arr, 10);
        print(twoSumOrder);
    }

}
